//
//  ShareWebViewController.m
//  reSearchDemo
//
//  Created by 科技 on 15/9/9.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "ShareWebViewController.h"
#import "LXActivity.h"
#import "SessionNewController.h"
#import "User.h"
#import "Session.h"
#import "Message.h"
#import "JSON.h"
@interface ShareWebViewController ()<LXActivityDelegate> {
    UIWebView *_webView;
    CommentType          cType;
}

@end

@implementation ShareWebViewController
-(ShareWebViewController *)initWithURL:(NSString *)path Message:(Message *)msg {
    self = [super init];
    if (self) {
        _path = path;
        _msg = msg;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"云库";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_more"] style:UIBarButtonItemStyleDone target:self action:@selector(ShareBtnAction:)];
    
    _webView = [[UIWebView alloc] initWithFrame:self.view.frame];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@",_path]]];
    [_webView loadRequest:request];
    [self.view addSubview:_webView];
}

-(void)ShareBtnAction:(UIBarButtonItem *)sender {
    NSArray *shareButtonTitleArray = [[NSArray alloc] init];
    NSArray *shareButtonImageNameArray = [[NSArray alloc] init];
    shareButtonTitleArray = @[@"传播给朋友",@"云分享",@"收藏",@"复制链接"];
    shareButtonImageNameArray = @[@"图标---传播给朋友",@"图标---云分享",@"图标---收藏",@"图标---复制链接"];
    LXActivity *lxActivity = [[LXActivity alloc] initWithTitle:@"分享" delegate:self cancelButtonTitle:@"取消" ShareButtonTitles:shareButtonTitleArray withShareButtonImagesName:shareButtonImageNameArray];
    [lxActivity showInView:self.view];
}

#pragma mark - LXActivityDelegate

- (void)didClickOnImageIndex:(NSInteger *)imageIndex
{
    DLog(@"%d",(int)imageIndex);
    switch ((int)imageIndex) {
        case 0:
        {
            // 转发新闻消息
            SessionNewController * con = [[SessionNewController alloc] init];
            con.isForword =
            con.isShowGroup = NO;
            
            Message * msg = [[Message alloc] init];
            NSMutableDictionary * dic = [NSMutableDictionary dictionary];
            [dic setObject:@"链接" forKey:@"uid"];
            [dic setObject:@"百度" forKey:@"nickname"];
            [dic setObject:@"icon" forKey:@"headsmall"];
            msg.typefile = forFileNameCard;
            msg.content = [dic JSONString];
            con.value = msg;
            
            [self pushViewController:con];
            
//            [self forwordWithMsg:_msg];
            //获取当前用户
//            User *user = [BSEngine currentUser];
//            Session * session = [Session getSessionWithID:user.uid];
//            if (!session) {
//                session = [Session sessionWithUser:user];
//            }
//            SessionNewController *sessionVC = [[SessionNewController alloc] initWithSession:session];
//            sessionVC.isForword = YES;
//            [self pushViewController:sessionVC];
            break;
        }
        case 1:
        {
            BOOL isShare = [super startRequest];
            [client addNewshare:nil content:_path lng:0.0 lat:0.0 address:nil visible:nil];
            if (isShare) {
                [self showText:@"分享成功"];
            }else {
                [self showText:@"分享失败"];
            }
            
            break;
        }
        case 2:
        {
            // 复制文字
            [[UIPasteboard generalPasteboard] setString:_path];
            break;
        }
        case 3:
        {
            NSMutableDictionary * dic = [NSMutableDictionary dictionary];
            [dic setObject:_path forKey:@"content"];
            [dic setObject:[NSString stringWithFormat:@"%d", forFileText]  forKey:@"typefile"];
            cType = forAddFav;
            NSString *uid = [BSEngine currentUserId];
            [client addfavorite:uid otherid:nil content:[dic JSONString]];
            
            break;
        }
        case 4:
        {
            
            break;
        }
        default:
            break;
    }
}

- (void)didClickOnCancelButton
{
    DLog(@"didClickOnCancelButton");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
